---
layout: m1x_soap
title: Create Attribute
---

<h3><a name="product_attribute.create-Module%3AProductAttributesAPI"></a>Module: Product Attributes API</h3>

<h4><a name="product_attribute.create-Resource%3Aproductattribute"></a>Resource: product_attribute</h4>


<h5><a name="product_attribute.create-Method%3A"></a>Method:</h5>

<ul>
	<li>product_attribute.create (SOAP V1)</li>
	<li>catalogProductAttributeCreate (SOAP V2)</li>
</ul>


<p>Allows you to create a new product attribute.</p>

<p><b>Arguments:</b></p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> sessionId </td>
<td> Session ID </td>
</tr>
<tr>
<td> array </td>
<td> data </td>
<td> Array of catalogProductAttributeEntityToCreate </td>
</tr>
</tbody></table>


<p><b>Returns:</b></p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> int </td>
<td> result </td>
<td> ID of the created attribute </td>
</tr>
</tbody></table>


<p>The <b>catalogProductAttributeEntityToCreate</b> content is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> attribute_code <br class="atl-forced-newline" /> </td>
<td> Attribute code </td>
</tr>
<tr>
<td> string <br class="atl-forced-newline" /> </td>
<td> frontend_input <br class="atl-forced-newline" /> </td>
<td> Attribute type <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> string <br class="atl-forced-newline" /> </td>
<td> scope <br class="atl-forced-newline" /> </td>
<td> Attribute scope. Possible values are as follows: 'store', 'website', or 'global' <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> string <br class="atl-forced-newline" /> </td>
<td> default_value <br class="atl-forced-newline" /> </td>
<td> Attribute default value </td>
</tr>
<tr>
<td> int </td>
<td> is_unique <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute is unique </td>
</tr>
<tr>
<td> int </td>
<td> is_required <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute is required <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> ArrayOfString </td>
<td> apply_to <br class="atl-forced-newline" /> </td>
<td> Apply to. Empty for "Apply to all" or array of the following possible values: 'simple', 'grouped', 'configurable', 'virtual', 'bundle', 'downloadable', 'giftcard' <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> int </td>
<td> is_configurable <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute can be used for configurable products <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> int <br class="atl-forced-newline" /> </td>
<td> is_searchable <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute can be used in Quick Search </td>
</tr>
<tr>
<td> int <br class="atl-forced-newline" /> </td>
<td> is_visible_in_advanced_search <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute can be used in Advanced Search </td>
</tr>
<tr>
<td> int <br class="atl-forced-newline" /> </td>
<td> is_comparable <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute can be compared on the frontend </td>
</tr>
<tr>
<td> int <br class="atl-forced-newline" /> </td>
<td> is_used_for_promo_rules <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute can be used for promo rules </td>
</tr>
<tr>
<td> int <br class="atl-forced-newline" /> </td>
<td> is_visible_on_front <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute is visible on the frontend </td>
</tr>
<tr>
<td> int <br class="atl-forced-newline" /> </td>
<td> used_in_product_listing <br class="atl-forced-newline" /> </td>
<td> Defines whether the attribute can be used in product listing </td>
</tr>
<tr>
<td> associativeArray </td>
<td> additional_fields <br class="atl-forced-newline" /> </td>
<td> Array of additional fields </td>
</tr>
<tr>
<td> array </td>
<td> frontend_label <br class="atl-forced-newline" /> </td>
<td> Array of catalogProductAttributeFrontendLabel </td>
</tr>
</tbody></table>


<p>The <b>catalogProductAttributeFrontendLabelEntity</b> content is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> store_id <br class="atl-forced-newline" /> </td>
<td> Store ID </td>
</tr>
<tr>
<td> string </td>
<td> label <br class="atl-forced-newline" /> </td>
<td> Text label </td>
</tr>
</tbody></table>

<p><b>Notes</b>: The "label" value for the "store_id" value set to 0 must be specified. An attribute cannot be created without specifying the label for store_id=0.</p>

<p>The <b>AdditionaFieldsEntity</b> array of additional fields for the <b>text</b> type is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> frontend_class </td>
<td> Input Validation for Store Owner. Possible values are as follows: 'validate-number' (Decimal Number), 'validate-digits' (Integer Number), 'validate-email', 'validate-url', 'validate-alpha' (Letters), 'validate-alphanum' (Letters (a-z, A-Z), or Numbers (0-9)) </td>
</tr>
<tr>
<td> boolean </td>
<td> is_html_allowed_on_front </td>
<td> Defines whether the HTML tags are allowed on the frontend </td>
</tr>
<tr>
<td> boolean </td>
<td> used_for_sort_by </td>
<td> Defines whether it is used for sorting in product listing </td>
</tr>
</tbody></table>


<p>The <b>AdditionaFieldsEntity</b> array of additional fields for the <b>text area</b> type is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> boolean </td>
<td> is_wysiwyg_enabled </td>
<td> Enable WYSIWYG flag </td>
</tr>
<tr>
<td> boolean </td>
<td> is_html_allowed_on_front </td>
<td> Defines whether the HTML tags are allowed on the frontend <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>


<p>The <b>AdditionaFieldsEntity</b> array of additional fields for the <b>date</b>和<b>boolean</b> types is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> boolean </td>
<td> used_for_sort_by </td>
<td> Defines whether it is used for sorting in product listing <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>


<p>The <b>AdditionaFieldsEntity</b> array of additional fields for the <b>multiselect</b> type is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> boolean </td>
<td> is_filterable </td>
<td> Defines whether it is used in layered navigation </td>
</tr>
<tr>
<td> boolean </td>
<td> is_filterable_in_search </td>
<td> Defines whether it is used in search results layered navigation </td>
</tr>
<tr>
<td> int </td>
<td> position </td>
<td> Position </td>
</tr>
</tbody></table>


<p>The <b>AdditionaFieldsEntity</b> array of additional fields for the <b>select</b>和<b>price</b> types is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> boolean </td>
<td> is_filterable </td>
<td> Defines whether it is used in layered navigation <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> boolean </td>
<td> is_filterable_in_search </td>
<td> Defines whether it is used in search results layered navigation <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> int </td>
<td> position </td>
<td> Position </td>
</tr>
<tr>
<td> boolean </td>
<td> used_for_sort_by </td>
<td> Defines whether it is used for sorting in product listing <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>


<p><b>Faults:</b></p>


<table><tbody>
<tr>
<th> Fault Code </th>
<th> Fault Message </th>
</tr>
<tr>
<td> 102 </td>
<td> Invalid request parameters. </td>
</tr>
<tr>
<td> 103 </td>
<td> Attribute code is invalid. Please use only letters (a-z), numbers (0-9) or underscore (_) in this field, first character should be a letter. </td>
</tr>
<tr>
<td> 104 </td>
<td> Incorrect attribute type. </td>
</tr>
<tr>
<td> 105 </td>
<td> Unable to save attribute. </td>
</tr>
</tbody></table>


<h4><a name="product_attribute.create-Examples"></a>Examples</h4>

<h5><a name="product_attribute.create-RequestExampleSOAPV1"></a>Request Example SOAP V1</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: php; gutter: false">&lt;?php

$client = new SoapClient('http://magentohost/api/soap/?wsdl');

// If some stuff requires api authentification,
// then get a session token
$session = $client-&gt;login('apiUser', 'apiKey');

$attributeToUpdate = array(
    "scope" =&gt; "global",
 "default_value" =&gt; "100",
    "frontend_input" =&gt; "text",
    "is_unique" =&gt; 0,
    "is_required" =&gt; 0,
    "is_configurable" =&gt; 0,
    "is_searchable" =&gt; 0,
    "is_visible_in_advanced_search" =&gt; 0,
    "used_in_product_listing" =&gt; 0,
    "additional_fields" =&gt; array(
        "is_filterable" =&gt; 1,
        "is_filterable_in_search" =&gt; 1,
        "position" =&gt; 1,
        "used_for_sort_by" =&gt; 1
    ),
    "frontend_label" =&gt; array(
        array(
            "store_id" =&gt; 0,
            "label" =&gt; "Updated attribute"
        )
    )
);


$attributeCode = 'code1';

$result = $client-&gt;call($session, 'product_attribute.update', array($attributeCode, $attributeToUpdate));
var_dump ($result);
 
// If you don't need the session anymore
//$client-&gt;endSession($session);

?&gt;</pre>
		</div>
</div></div>


<h5><a name="product_attribute.create-RequestExampleSOAPV2"></a>Request Example SOAP V2</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: php; gutter: false">&lt;?php
//ini_set("soap.wsdl_cache_enabled", 0);

$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

//V2
$session = $client-&gt;login('apiUser', 'apiKey');

// V2 WS-I Mode
//$response = $client-&gt;login(array('username' =&gt; 'apiUser', 'apiKey' =&gt; 'apiKey'));
//$session = $response-&gt;result;


//v2

$data = array(
   "attribute_code" =&gt; "test_attribute",
   "frontend_input" =&gt; "text",
   "scope" =&gt; "1",
   "default_value" =&gt; "1",
   "is_unique" =&gt; 0,
   "is_required" =&gt; 0,
   "apply_to" =&gt; array("simple"),
   "is_configurable" =&gt; 0,
   "is_searchable" =&gt; 0,
   "is_visible_in_advanced_search" =&gt; 0,
   "is_comparable" =&gt; 0,
   "is_used_for_promo_rules" =&gt; 0,
   "is_visible_on_front" =&gt; 0,
   "used_in_product_listing" =&gt; 0,
   "additional_fields" =&gt; array(),
   "frontend_label" =&gt; array(array("store_id" =&gt; "0", "label" =&gt; "some label"))
  );

$orders = $client-&gt;catalogProductAttributeCreate($session, $data);



//V2 WSI
//WSDL WSI Sample is not complete
//$result = $client-&gt;catalogProductAttributeCreate(array("sessionId" =&gt; $session, "data" =&gt; $data));
//$orders = $result-&gt;result-&gt;complexObjectArray;

echo 'Number of results: ' . count($orders) . '&lt;br/&gt;';
var_dump ($orders);
?&gt;</pre>
		</div>
</div></div>

				    
Create the Magento文件系统所有者                   			    
